<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title">
        <div class="page-title-con">
            <span>新建人员交接</span>
            <div class="move_title"></div>
            <?php include "../public/sub.php";?>
        </div>
    </div>
    <div class="main-container">
        <div class="block-generic">


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>交接类型</label>
                        <div class="layui-input-block">
                            <div class="radio-block" id="typeDiv"> </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>交接人</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=jiaoer&type=user&single=1&page=user_take_call', '770px', '490px');"></div>
                                <div class="tanxiannei" id="jiaoer"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=jiaoer&type=user&single=1&page=user_take_call', '770px', '490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="jiaoer_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>接手人</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=jieer&type=user&single=1', '770px', '490px');"></div>
                                <div class="tanxiannei" id="jieer"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=jieer&type=user&single=1', '770px', '490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="jieer_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">交接原因</label>
                        <div class="layui-input-block">
                            <input type="text" name="yuan" id="yuan" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">是否停用交接人账号</label>
                        <div class="layui-input-block">
                            <div class="radio-block">
                                <input type="radio" name="isting" value="1" title="是">
                                <input type="radio" name="isting" checked value="0" title="否">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>交接事项</label>
                        <div class="layui-input-block" id="qingDiv">
                            <div class="radio-block" >

                            </div>
                        </div>
                        <div class="layui-input-block layui-hide" id="piDiv">
                            <div class="radio-block">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>交接内容</label>
                        <div class="layui-input-block">
                            <div id="con"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfo.php'?>
        </div>


    </div>
</form>
<script>
    $("#commentForm").validate({
        rules: {

        },
        messages:{

        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();
        facade.ajax({type: 'get', url: ask_user_take_add}).done(function(res){
            if (res.code === 2000) {
                var typearr = res.data.typearr;
                var qingarr = res.data.qingarr;
                var piarr = res.data.piarr;

                var type_str = '';
                for (var key in typearr){
                    if(key == 1){
                        type_str += '<input type="radio" name="type" lay-filter="type" checked value="'+key+'" title="'+typearr[key]+'">';
                    }else{
                        type_str += '<input type="radio" name="type" lay-filter="type" value="'+key+'" title="'+typearr[key]+'">';
                    }
                }
                $('#typeDiv').html(type_str);



                var qing_str = '';
                for (var key in qingarr){
                    if(key == 1){
                        qing_str += '<input type="radio" name="qing" lay-filter="qing" checked value="'+key+'" title="'+qingarr[key]+'">';
                    }else{
                        qing_str += '<input type="radio" name="qing" lay-filter="qing" value="'+key+'" title="'+qingarr[key]+'">';
                    }
                }
                $('#qingDiv').html(qing_str);

                var pi_str = '';
                for (var key in piarr){
                    if(key == 1){
                        pi_str += '<input type="radio" name="pi" lay-filter="pi" checked value="'+key+'" title="'+piarr[key]+'">';
                    }else{
                        pi_str += '<input type="radio" name="pi" lay-filter="pi" value="'+key+'" title="'+piarr[key]+'">';
                    }
                }
                $('#piDiv').html(pi_str);


                var conXmObj = xmselect_duo('con', [], '', function (res) {

                });



                public_upload_file_load('upload_files');
                render_from();
            }
        });




        form.on('radio(type)', function(data){
            if(data.value == 1){
                $("#qingDiv").removeClass('layui-hide');
                $("#piDiv").addClass('layui-hide');
            }
            if(data.value == 2){
                $("#qingDiv").addClass('layui-hide');
                $("#piDiv").removeClass('layui-hide');
            }
            get_con_arr();
        });
        form.on('radio(qing)', function(data){
            get_con_arr();
        });
        form.on('radio(pi)', function(data){
            get_con_arr();
        });

        form.on('submit(add)', function(data){

            data.field.jiaoer = tan_tags_getvalue("#jiaoer", 'user');
            data.field.jieer = tan_tags_getvalue("#jieer", 'user');

            var validRes = $("#commentForm").valid();
            if(!data.field.jiaoer){
                $("#jiaoer").parents('.tanxian').addClass('tanerror');
                $('#jiaoer_tanerror').text('请选择');
                validRes = false;
            }else{
                $("#jiaoer").parents('.tanxian').removeClass('tanerror');
                $('#jiaoer_tanerror').text('');
            }

            if(!data.field.jieer){
                $("#jieer").parents('.tanxian').addClass('tanerror');
                $('#jieer_tanerror').text('请选择');
                validRes = false;
            }else{
                $("#jieer").parents('.tanxian').removeClass('tanerror');
                $('#jieer_tanerror').text('');
            }

            if(!validRes){return false;}

            data.field.shi = '';
            if(data.field.type == 1){
                data.field.shi = data.field.qing
            }else{
                data.field.shi = data.field.pi
            }

            delete data.field.qing
            delete data.field.pi

            data.field.files = public_upload_file_value('upload_files');


            layer.confirm("<div class='tit'>此操作不可撤销，请谨慎操作！</div><div class='exp'></div>", {
                    title:'操作确认',
                    icon: 3,
                    area:['450px','220px'],
                    btn:['确定']
                }, function(conindex){
                    facade.ajax({url: ask_user_take_add, data:data.field}).done(function(res){
                        if (res.code === 2000) {
                            dataPostTimeOut();
                        }
                        layer.close(conindex);
                    });
                }
            )


            return false;
        });

    });


    function get_con_arr() {
        xmselect_duo('con', [], '', function (res) {});

        var jiaoer = tan_tags_getvalue("#jiaoer", 'user');
        if(!jiaoer){
            return false;
        }

        var shi = '';
        var type =  $('input[name="type"]:checked').val();
        if(type == 1){
            shi = $('input[name="qing"]:checked').val();
        }else{
            shi = $('input[name="pi"]:checked').val();
        }
        if(!shi){
            return false;
        }
        facade.ajax({type: 'post', url: ask_user_take_shi, data:{jiaoer: jiaoer, shi:shi}}).done(function(res){
            if (res.code === 2000) {
                console.log(res.data)
                xmselect_duo('con', res.data, [], function (res) {});
                render_from();
            }
        });
    }





</script>
</body>
</html>
